package com.taptech.doufu.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.taptech.doufu.bean.personalcenter.PersonalCardInfo;
import com.taptech.doufu.util.ScreenUtil2;
import com.taptech.doufu.util.TTLog;
import com.taptech.doufu.R;
import com.taptech.doufu.bean.HomeTopBean;
import com.taptech.doufu.bean.ImageBean;
import com.taptech.doufu.bean.PersonalNoteBean;
import com.taptech.doufu.bean.UserBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.ui.view.drawcircle.DoufuTagsAdapter;
import com.taptech.doufu.ui.view.drawcircle.PersonalNoteImgListViewAdapter;
import com.taptech.doufu.bean.ShareBeansInfo;
import com.taptech.doufu.listener.HttpResponseListener;
import com.taptech.doufu.services.personalcenter.AccountService;
import com.taptech.doufu.services.personalcenter.PersonalInfoService;
import com.taptech.doufu.services.HomeMainServices;
import com.taptech.doufu.services.PersonalNoteService;
import com.taptech.doufu.util.DiaobaoUtil;
import com.taptech.doufu.util.GlideUtil;
import com.taptech.doufu.util.UIUtil;
import com.taptech.doufu.net.httputils.HttpResponseObject;
import com.taptech.doufu.ui.view.DiaobaoTextView;
import com.taptech.doufu.ui.view.DoufuTagsView;
import com.taptech.doufu.ui.view.FlowerAndGiftManager;
import com.taptech.doufu.ui.view.ListviewInScrollView;
import com.taptech.doufu.ui.view.ShareTopPopupWindow;
import com.taptech.doufu.ui.view.WaitDialog;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;

/**
 * Created by lsy on 2015/7/3.
 */

public class PersonalNoteDesActivity implements View.OnClickListener, HttpResponseListener {

    /*
     ================UI控件===========================
     */ Context mContext;
    //加载等待窗
    WaitDialog mWaitDialog;
    //编辑、收藏、分享
    private PopupWindow mMorePopupWindow;
    private ImageView mOtherMoreBtn;
    private LinearLayout mCollectBtn;
    private LinearLayout mShareBtn;
    private LinearLayout mReportBtn;
    private ImageView mCollectBtnImg;
    private TextView mCollectBtnText;
    // 举报上面的分隔线
    private View mReportDiliverLine;


    //作品名
    private TextView mDrawNameView;
    //作品标签
    private DoufuTagsView mTagsView;
    private DoufuTagsAdapter tagsAdapter;
    List<String> tagList;
    private ImageView mMoreTagBtn;
    //用户头像、勋章、名字、发表时间和关注按钮
    private ImageView mUserImg, mUserMedalImg;
    private TextView mAuthorNameView, mUgcTimeView;
    private LinearLayout mAttentionAuthorBtn;
    private ImageView mFlowingBtnImg;
    private TextView mAttentionTextView;
    //作品文字内容
    private DiaobaoTextView mTextContentView;
    //作品图片列表
    private ListviewInScrollView mImgListView;
    private PersonalNoteImgListViewAdapter mImgListViewAdapter;


    // 绘画或COSER的特殊部分
    private TextView mSpecialContentText;
    // 献花和打赏组件
    private FlowerAndGiftManager flowerAndGiftManager;


    /*
    ======================================数据=======================================
    */
    private String id;
    private String object_type = PersonalNoteService.OBJECT_TYPE_NOTE;
    private PersonalNoteBean bean;
    private List<ImageBean> mImgDataList;
    private LinkedHashSet<String> mImageUrls;
    private LinkedHashSet<String> mOriginImageUrls;
    private ArrayList<Integer> mImageHeights;
    private ArrayList<Integer> mImageWidths;
    private boolean isCollectExist = false;

    private boolean mAbleToDownload = false;

    private ImageView topBackBtn;
    private ImageView topShareBtn;
    private Handler mhandler;

    public void init(Context context, View view, String id, String object_type) {
        mContext = context;
        initData(id, object_type);
        initView(view);

        if (id != null && !id.equals("")) {
            PersonalNoteService.getInstance().loadPersonalNoteDes(PersonalNoteDesActivity.this, id);
            //PersonalNoteService.getInstance().loadFlowerList(PersonalNoteDesActivity.this, id, object_type, "");
            PersonalNoteService.getInstance().judgeCollectExist(PersonalNoteDesActivity.this, id, object_type);
        }
    }


    private void initData(String id, String object_type) {

        this.id = id;
        this.object_type = object_type;
        //根据object_type决定specialview的显示与显示内容
        mImageUrls = new LinkedHashSet<String>();
        mOriginImageUrls = new LinkedHashSet<String>();
        mImageHeights = new ArrayList<Integer>();
        mImageWidths = new ArrayList<Integer>();
    }

    int position;

  /*  public void getBottomView()
    {   return;
    }*/

    private void initView(View view) {

        topBackBtn = (ImageView) view.findViewById(R.id.finish_layout);
        topBackBtn.setOnClickListener(this);
        topShareBtn = (ImageView) view.findViewById(R.id.draw_share_btn);
        topShareBtn.setOnClickListener(this);

        mAttentionAuthorBtn = (LinearLayout) view.findViewById(R.id.personal_follow_btn);
        mAttentionAuthorBtn.setOnClickListener(this);
        mAttentionTextView = (TextView) view.findViewById(R.id.follow_button_textview);
        //作品信息
        mOtherMoreBtn = (ImageView) view.findViewById(R.id.draw_share_btn);

        mDrawNameView = (TextView) view.findViewById(R.id.draw_title_text);
        mUserImg = (ImageView) view.findViewById(R.id.draw_user_headimg);
        mUserImg.setOnClickListener(this);
        mUserImg.setImageResource(R.drawable.default_head_img);
        mUserMedalImg = (ImageView) view.findViewById(R.id.draw_user_medalimg);
        mAuthorNameView = (TextView) view.findViewById(R.id.ugc_author_name);
        mFlowingBtnImg = (ImageView) view.findViewById(R.id.follow_img);
        mUgcTimeView = (TextView) view.findViewById(R.id.draw_ugc_time);
        mTextContentView = (DiaobaoTextView) view.findViewById(R.id.draw_text_content);
        mImgListView = (ListviewInScrollView) view.findViewById(R.id.draw_img_listview);
        mImgListView.setLayerType(View.LAYER_TYPE_NONE, null);

        mImgListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                PersonalNoteService.getInstance().enterPersonalNoteBigImage(mContext, mImageUrls, mOriginImageUrls, i, mImageWidths, mImageHeights, mAbleToDownload);
            }
        });


        mImgDataList = new ArrayList<ImageBean>();
        mImgListViewAdapter = new PersonalNoteImgListViewAdapter(mContext, mImgDataList);
        mImgListView.setAdapter(mImgListViewAdapter);

        //初始化标签控件
        initTagsView(view);

        //初始化绘画和COSER的特殊部分
        mSpecialContentText = (TextView) view.findViewById(R.id.special_content_text);
        // 更多选项弹窗初始化
        makeOtherMoreWindow();
        // 加载等待窗
        initWaitWindow();
        TTLog.d("tag", "this des activity object  is ================" + object_type);
        flowerAndGiftManager = FlowerAndGiftManager.initInView(mContext, view);

    }

    float mLastY = 0, y_0;
    float ABS = 8.0f;

    private void handleSpecialViewDisplay(String object_type, PersonalNoteBean noteBean) {
        if (object_type.equals(PersonalNoteService.OBJECT_TYPE_NOTE)) {
            mSpecialContentText.setVisibility(View.GONE);

        } else if (object_type.equals(PersonalNoteService.OBJECT_TYPE_DRAW)) {
            mSpecialContentText.setVisibility(View.VISIBLE);
            if (noteBean != null && noteBean.getDrawing_tools() != null) {
                mSpecialContentText.setText("工具：" + noteBean.getDrawing_tools());
            }
        } else if (object_type.equals(PersonalNoteService.OBJECT_TYPE_COSER)) {
            mSpecialContentText.setVisibility(View.VISIBLE);
            if (noteBean != null && noteBean.getCosplay_actor() != null && noteBean.getCosplay_role() != null) {
                mSpecialContentText.setText("" + noteBean.getCosplay_role());
            }
        }
    }


    @Override

    public void handleResponse(int handleType, HttpResponseObject response) {
        if (response == null) {
            return;
        }

        if (response.getStatus() == 0) {
            if (mWaitDialog != null && mWaitDialog.isShowing()) {
                mWaitDialog.dismiss();
            }
            switch (handleType) {
                case PersonalNoteService.HANDLE_TYPE_LOAD_SINGLE_NOTE:
                    handleNoteInfo(response);
                    break;
                // 判断是否收藏
                case PersonalNoteService.HANDLE_TYPE_JUDGE_COLLECTION_EXIST:
                    handleCollectExist(response);
                    break;

                case PersonalNoteService.HANDLE_TYPE_ADD_COLLECT:
                    handleAddCollect(response);
                    break;
                case PersonalNoteService.HANDLE_TYPE_REMOVE_COLLECT:
                    handleRemoveCollect(response);
                    break;

                // 举报
                case NewCpDesActivity.HANDLE_LOAD_REPORT_INFO:
                    UIUtil.toastMessage(mContext, "我们将尽快审核，请继续愉快地玩耍吧！");
                    break;
            }

        } else {
            if (response.getUser_msg() != null) {
                UIUtil.toastMessage(mContext, response.getUser_msg());
            } else {
                UIUtil.toastMessage(mContext, Constant.loadingFail);
            }
        }
    }

    @Override

    public void onClick(View view) {
        switch (view.getId()) {
            // 关注
            case R.id.personal_follow_btn:
                followAuthor(bean.getUser());
                break;
            case R.id.draw_user_headimg:
                if (bean != null && bean.getUser_id() != null) {
                    UserDetailActivity.Companion.startActivity(mContext,bean.getUser_id());
                }
                break;
            // 执行收藏
            case R.id.popup_reader_more_collect:

                if (mMorePopupWindow != null && mMorePopupWindow.isShowing()) {
                    mMorePopupWindow.dismiss();
                    if (!isCollectExist) {
                        PersonalNoteService.getInstance().addCollectToNote(this, id, object_type);
                    } else {
                        PersonalNoteService.getInstance().removeCollectTONote(this, id, object_type);
                    }
                }
                break;
            // 分享
            case R.id.popup_reader_more_share:

                if (mMorePopupWindow != null && mMorePopupWindow.isShowing()) {
                    mMorePopupWindow.dismiss();
                    topShare();
                }
                break;
            // 举报
            case R.id.popup_reader_more_report:

                if (mMorePopupWindow != null && mMorePopupWindow.isShowing()) {
                    mMorePopupWindow.dismiss();
                    topReport();
                }
                break;
            // 滑动标签到底
            case R.id.more_tags_btn:

                if (mMoreTagBtn != null && mMoreTagBtn.getVisibility() == View.VISIBLE) {
                    mTagsView.smoothScrollToPosition(tagsAdapter.getItemCount() - 1);
                }
                break;
            // 查看详细送花列表
            case R.id.flower_sum:
                Intent rankFlower = new Intent(mContext, FlowerRankActivity.class);
                rankFlower.putExtra(Constant.OBJECT_TYPE, object_type);
                rankFlower.putExtra(Constant.NOTE_ID, id);
                mContext.startActivity(rankFlower);
                break;
            // 分享
            case R.id.draw_share_btn:
                showMorePopupWindow();
                break;
            // 退出
            case R.id.finish_layout:
                Activity activity = (Activity) mContext;
                activity.finish();
                break;
        }
    }

    /**
     * 进入界面时的等待窗
     */

    private void initWaitWindow() {
        mWaitDialog = new WaitDialog(mContext, R.style.loadNovelDialog, "");
        mWaitDialog.setCanceledOnTouchOutside(false);
        mWaitDialog.show();
    }

    /**
     * 关注模块
     */
    // 显示已关注
    private void handleFollowAuthor(UserBean userBean) {
        if (userBean == null) {
            return;
        }
        if (AccountService.getInstance().isUserSelf(userBean.getUserId())) {
            mAttentionAuthorBtn.setVisibility(View.GONE);
            return;
        } else {
            mAttentionAuthorBtn.setVisibility(View.VISIBLE);
        }
        if (userBean.getFollowing() != null) {
            if (userBean.getFollowing().equals("1")) {
                mAttentionTextView.setText("已关注");
                mFlowingBtnImg.setImageResource(R.drawable.novel_attention_select);
                //mFollowBtn.setImageResource(R.drawable.followed_btn_draw);
            } else if (userBean.getFollowing().equals("0")) {
                mAttentionTextView.setText("关注");
                mFlowingBtnImg.setImageResource(R.drawable.novel_attention_default);

                //mFollowBtn.setImageResource(R.drawable.follow_btn_draw);
            }
        }
    }

    // 点击关注按钮

    private void followAuthor(final UserBean mUserBean) {
        if (mUserBean == null) {
            return;
        }
        if (AccountService.getInstance().isLogin()) {
            if (mUserBean.getFollowing() == null) {
                return;
            }

            if (mUserBean.getFollowing().equals("1")) {
                UIUtil.showEnsureDialog((Activity) mContext, "确定取消关注？", new UIUtil.EnsureListener() {
                    @Override
                    public void sure() {
                        PersonalInfoService.getInstance().cancelAttention(mUserBean.getUserId(), new HttpResponseListener() {

                            @Override
                            public void handleResponse(int handleType, HttpResponseObject response) {
                                if (response.getStatus() == 0) {
                                    UIUtil.toastMessage(mContext, "不能做朋友了");
                                    PersonalInfoService.getInstance().delMyAttentions(mUserBean.getUserId());
                                    mUserBean.setFollowing("0");
                                    mAttentionTextView.setText("关注");
                                    mFlowingBtnImg.setImageResource(R.drawable.novel_attention_default);


                                } else {
                                    UIUtil.toastMessage(mContext, "取消关注失败");
                                }

                            }
                        }, (Activity) mContext);

                    }

                    @Override

                    public void cancel() {

                    }
                });


            } else {

                PersonalInfoService.getInstance().addAttention(mUserBean.getUserId(), new HttpResponseListener() {

                    @Override
                    public void handleResponse(int handleType, HttpResponseObject response) {

                        if (response.getStatus() == 0) {

                            if (mUserBean != null) {
                                PersonalInfoService.getInstance().addMyAttentions(getPersonalCardInfo(mUserBean));
                            }
                            Log.d("tag", "关注列表长度为===========" + PersonalInfoService.getInstance().getAttentions().size());

                            UIUtil.toastMessage(mContext, "关注成“攻”");
                            mAttentionTextView.setText("已关注");
                            mFlowingBtnImg.setImageResource(R.drawable.novel_attention_select);
                            mUserBean.setFollowing("1");


                        } else {
                            UIUtil.toastMessage(mContext, "添加关注失败");
                        }

                    }
                }, (Activity) mContext);

            }

        } else {
            AccountService.getInstance().jumpToLogin();
        }
    }


    private PersonalCardInfo getPersonalCardInfo(UserBean userBean){
        PersonalCardInfo bean = new PersonalCardInfo();
        bean.setUid(userBean.getUserId());
        bean.setNickname(userBean.getName());
        bean.setHead_image(userBean.getIcon());
        bean.setUser_signature(userBean.getSignature());
        bean.setSocial_nickname(userBean.getName());
        bean.setUser_head_img(userBean.getUser_head_img());
        bean.setMedal(userBean.getMedal());
        bean.setType(userBean.getType());
        bean.setFollowing(userBean.getFollowing());
        return bean;
    }

    /**
     * 更多模块
     */
    // 更多选项UI初始化
    private void makeOtherMoreWindow() {
        View otherMoreView = LayoutInflater.from(mContext).inflate(R.layout.popup_reader_more_panel, null);
        mCollectBtn = (LinearLayout) otherMoreView.findViewById(R.id.popup_reader_more_collect);
        mCollectBtn.setOnClickListener(this);
        mCollectBtnImg = (ImageView) otherMoreView.findViewById(R.id.popup_reader_more_iv_collect);
        mCollectBtnText = (TextView) otherMoreView.findViewById(R.id.popup_reader_more_tv_collect);
        mShareBtn = (LinearLayout) otherMoreView.findViewById(R.id.popup_reader_more_share);
        mShareBtn.setVisibility(View.VISIBLE);
        mShareBtn.setOnClickListener(this);
        mReportBtn = (LinearLayout) otherMoreView.findViewById(R.id.popup_reader_more_report);
        mReportBtn.setVisibility(View.VISIBLE);
        mReportBtn.setOnClickListener(this);
        mReportDiliverLine = otherMoreView.findViewById(R.id.popup_reader_more_flow_ruel_line);
        mReportDiliverLine.setVisibility(View.VISIBLE);

        mMorePopupWindow = new PopupWindow(otherMoreView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mMorePopupWindow.setAnimationStyle(R.style.Animation_Right_Left);
        mMorePopupWindow.setBackgroundDrawable(new ColorDrawable());
    }

    // 更多选项弹窗出现

    public void showMorePopupWindow() {
        TTLog.d("tag", "showMorePopupWindow ============ click");
        try {
            if (mMorePopupWindow == null) {
                return;
            }
            Activity activity = (Activity) mContext;
            mMorePopupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.TOP | Gravity.RIGHT, ScreenUtil2.dip2px(4), ScreenUtil2.dip2px(60));

            mMorePopupWindow.setFocusable(true);
            mMorePopupWindow.setOutsideTouchable(true);
            mMorePopupWindow.update();
            TTLog.d("tag", "showMorePopupWindow ============ succeed");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 举报模块
     */

    private void topReport() {
        if (bean == null) {
            return;
        }
        HomeMainServices.reportContentRequest(mContext, bean.getUser_id(), bean.getObject_type(), bean.getId());

        //PublicInfoService.getInstance().loadReportInfo(mContext , id, PersonalNoteDesActivity.this, object_type);
    }

    /**
     * 分享模块
     */

    private void topShare() {
        if (bean == null) {
            return;
        }
        ShareTopPopupWindow menuWindow = new ShareTopPopupWindow((Activity) mContext);
        ShareBeansInfo shareInfo = new ShareBeansInfo(ShareBeansInfo.NOTE_SHARE_FLAG);
        shareInfo.setShartText(bean.getTitle());
        shareInfo.setTitle(bean.getTitle());
        shareInfo.setDescription(bean.getContent());
        shareInfo.setShareUrl(bean.getShare_url());
        shareInfo.setObject_type(object_type);

        if (bean.getUser() != null) {
            shareInfo.setArticleAuthor(bean.getUser().getName());
        } else {
            shareInfo.setArticleAuthor("佚名");
        }
        String[] tags = bean.getTags().split("\\s+");
        shareInfo.setTags(tags);

        if (mImgDataList != null && mImgDataList.size() > 0) {
            shareInfo.setImagUrl("http://imgold2.doufu.la/" + mImgDataList.get(0).getThumbnail_path());
        }
        if (bean.getId() != null) {
            shareInfo.setId(bean.getId());
        } else {
            shareInfo.setId(id);
        }

        menuWindow.setShareBeans(shareInfo);
        shareInfo.setNoteBean(bean);

        if (bean != null) {
            HomeTopBean shareData = new HomeTopBean();
            shareData.setTitle(bean.getTitle());
            shareData.setContent(bean.getContent());
            shareData.setObject_type(bean.getObject_type());
            shareInfo.setShareData(shareData);
            shareInfo.setShareUrl(bean.getShare_url());

        }
        // 显示窗口
        menuWindow.showAsDropDown(mOtherMoreBtn, 0, 0); // 设置layout在PopupWindow中显示的位置

    }

    /**
     * 收藏模块
     */

    private void handleCollectExist(HttpResponseObject response) {
        final JSONObject jsonObject = (JSONObject) response.getData();
        try {
            isCollectExist = jsonObject.getBoolean("has_fav");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (isCollectExist) {
            mCollectBtnImg.setImageResource(R.drawable.btn_reader_collect_pressed);
            mCollectBtnText.setText("已收藏");

        } else {
            mCollectBtnImg.setImageResource(R.drawable.btn_reader_collect_normal);
            mCollectBtnText.setText("收藏");
        }
    }


    private void handleAddCollect(HttpResponseObject response) {
        if (response.getFail_code() == 0 && response.getStatus() == 0) {
            isCollectExist = true;
            mCollectBtnImg.setImageResource(R.drawable.btn_reader_collect_pressed);
            UIUtil.toastMessage(mContext, "收藏成功");
            mCollectBtnText.setText("已收藏");
        }
    }


    private void handleRemoveCollect(HttpResponseObject response) {
        if (response.getFail_code() == 0 && response.getStatus() == 0) {
            isCollectExist = false;
            mCollectBtnImg.setImageResource(R.drawable.btn_reader_collect_normal);
            UIUtil.toastMessage(mContext, "已取消收藏");
            mCollectBtnText.setText("收藏");
        }
    }


    // 拉取评论


    /**
     * 作品展现模块
     */
    //处理作品信息的展现
    private void handleNoteInfo(HttpResponseObject respon) {
        JSONObject data = (JSONObject) respon.getData();
        if (bean == null) {
            bean = new PersonalNoteBean();
        }
        try {
            TTLog.d("tag", "catch the journal error " + data.getString("journal"));
            String checkString = data.getString("journal");
            if (checkString != null && checkString.equals("false")) {
                UIUtil.toastMessage(mContext, "作品已删除");
                //finish();
                return;
            }
            bean.setJson2(data.getJSONObject("journal"));

        } catch (JSONException e) {

        }

        handleNoteInfoView(bean);
        try {
            if (data.has("has_permissions") && data.getString("has_permissions").equals("1")){
                flowerAndGiftManager.setGiftLayoutVisiable(true);
            } else {
                flowerAndGiftManager.setGiftLayoutVisiable(false);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    // 显示作品基本信息

    private void handleNoteInfoView(PersonalNoteBean noteBean) {
        // 判断能否下载
        if (noteBean.getOriginal() != null) {
            if (noteBean.getOriginal().equals("1")) {
                mAbleToDownload = true;
            } else {
                mAbleToDownload = false;
            }

        }


        if (noteBean.getTitle() != null) {
            mDrawNameView.setText(noteBean.getTitle());

            if (noteBean.getTitle().equals("")) {
                mDrawNameView.setVisibility(View.GONE);
            } else {
                mDrawNameView.setVisibility(View.VISIBLE);
            }
        } else {
            mDrawNameView.setVisibility(View.GONE);

        }
        if (noteBean.getUser() != null && noteBean.getUser().getName() != null) {
            mAuthorNameView.setText(noteBean.getUser().getName());
        }
        if (noteBean.getCreated_at() != null) {
            if (noteBean.getCreated_at().contains(" ")) {
                mUgcTimeView.setText(noteBean.getCreated_at());
            } else {
                mUgcTimeView.setText(DiaobaoUtil.seconds2TimeString(Long.parseLong(noteBean.getCreated_at())));
            }
        }
        if (noteBean.getContent() != null) {
            mTextContentView.setClickMode((byte) (DiaobaoTextView.AtClickEnable | DiaobaoTextView.LinkClickEnable));
            mTextContentView.setDiaobaoText(noteBean.getContent());

            if (noteBean.getContent().equals("")) {
                mTextContentView.setVisibility(View.GONE);

            } else {
                mTextContentView.setVisibility(View.VISIBLE);
            }
        } else {
            mTextContentView.setVisibility(View.GONE);
        }
        if (noteBean.getUser() != null) {
            GlideUtil.displayCircleImage(mUserImg, noteBean.getUser().getIcon());
            DiaobaoUtil.setMedalImgView(noteBean.getUser().getMedal(), mUserMedalImg);
        }

        if (noteBean.getImages() != null && noteBean.getImages().length > 0) {
            List<ImageBean> tempList = Arrays.asList(noteBean.getImages());
            for (ImageBean imageBean : noteBean.getImages()) {
                mImageUrls.add(imageBean.getThumbnail3_path());
                mOriginImageUrls.add(imageBean.getPath());
                mImageHeights.add(Integer.valueOf(imageBean.getThumbnail_height()));
                mImageWidths.add(Integer.valueOf(imageBean.getThumbnail_width()));
            }
            // 获取图片最高度
            mImgListView.setLayoutHeight(mImgListView.calculateHeight(noteBean.getImages(), ScreenUtil2.getScreenWidthPixel((Activity) mContext)));
            mImgDataList.addAll(tempList);

            if (tempList != null) {
                TTLog.d("tag", "display the img =datalist===size===============" + tempList.size());
            }
            mImgListViewAdapter.notifyDataSetChanged();
        }
        //显示收藏与否，this is err it should be in handlerespon
        handleSpecialViewDisplay(object_type, noteBean);
        // 标签显示
        String[] tags = noteBean.getTags().split("\\s+");
        List<String> tempList = Arrays.asList(tags);
        tagList.clear();
        tagList.addAll(tempList);
        tagsAdapter.notifyDataSetChanged();
        // TEST
        mTagsView.requestFocus();


        // 关注按钮
        handleFollowAuthor(noteBean.getUser());
        flowerAndGiftManager.setFlowerAndGiftManagerInfo(bean);

    }

    public void setTagMoreBtnVisible() {
        if (mTagsView.computeHorizontalScrollExtent() >= mTagsView.computeHorizontalScrollRange()) {
            mMoreTagBtn.setVisibility(View.GONE);
        } else {
            mMoreTagBtn.setVisibility(View.VISIBLE);
        }
    }


    /**
     * 标签模块
     */
    //标签控件初始化
    private void initTagsView(View view) {
        mMoreTagBtn = (ImageView) view.findViewById(R.id.more_tags_btn);

        mMoreTagBtn.setOnClickListener(this);
        mTagsView = (DoufuTagsView) view.findViewById(R.id.draw_tags_layout);
        RecyclerView.LayoutManager layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL);
        mTagsView.setLayoutManager(layoutManager);
        tagList = new ArrayList<String>();
        tagsAdapter = new DoufuTagsAdapter(mContext, tagList, object_type);
        mTagsView.setAdapter(tagsAdapter);

        mTagsView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override

            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
            }
        });
    }


    public void setHandler(Handler mhandler) {
        this.mhandler = mhandler;
    }


    /*public void topBack(View view)
    {
        finish();
    }*/
}